/*
 * NewClass.java
 *
 * Created on 1 de marzo de 2007, 09:06 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package tedexis.mercurio.transformers;

import gurulab.maya.common.PhoneAddress;
import gurulab.merlin.core.envelope.Envelope;
import gurulab.merlin.core.router.EnvelopeTransformer;

/**
 *
 * @author nettrade
 */
public class NewClass implements EnvelopeTransformer {    
    
    public void transform(Envelope envelope) {
    	
        if (envelope.getDestinationRoute().getPeer().equals("wau")) {
            PhoneAddress phoneAdd = (PhoneAddress)envelope.getDestination();
            phoneAdd.setCrude(false);
            int startlocal = Integer.parseInt(phoneAdd.getLocal().substring(0, 3));
            int startlocal2 = Integer.parseInt(phoneAdd.getLocal().substring(0, 4));
            String str = "";
            
            if (startlocal >= 656 && startlocal <= 664) {//CDMA/TDMA (078)
                str = "078" + phoneAdd.getCountryCode() + phoneAdd.getLocal();
                phoneAdd.setNumber(str);
            }
            if ((startlocal == 648)|| (startlocal == 647)  || (startlocal == 649)) {//GSM (152)
                if ((startlocal2 >= 6480 && startlocal2 <= 6489) || startlocal2 == 6471 || startlocal2 <= 6491) {//GSM (152)
                    str = "152" + phoneAdd.getCountryCode() + phoneAdd.getLocal();
                    phoneAdd.setNumber(str);
                }
            }
            if ((startlocal >= 650 && startlocal <= 653) || (startlocal >= 665 && startlocal <= 6672)) {//Cable&Wireless(117)
                str = "117" + phoneAdd.getCountryCode() + phoneAdd.getLocal();
                phoneAdd.setNumber(str);
            }
            envelope.setDestination(phoneAdd);
        }
    }
    
}
